home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / sap.arc / SAP.C < prev    next >
C/C++ Source or Header  |  1988-04-06  |  6KB  |  168 lines

  1. /*****************************************************************************
  2.  *
  3.  * Program Name:  SAP_Routines
  4.  *
  5.  * Filename:      sap.c
  6.  *
  7.  * Date Created:  March 22, 1988
  8.  *
  9.  * Programmers:      Bryan Sparks
  10.  *
  11.  * Files used:      comm.h sapa.asm
  12.  *
  13.  * Comments:      This is a plug-in module that will do service advertising.
  14.  *
  15.  ****************************************************************************/
  16.  
  17. #include "comm.h"
  18.  
  19. /* We will keep this pointer around so as to keep track of the */
  20. /* oscillating ECB.  We will need to know where it is later so we */
  21. /* can cancel the event associated with that ECB. */
  22. ECB        *DownECBPointer;
  23.  
  24. void StartSAPOscillationRoutines( ServerName, ServerType, ServerSocket )
  25. char    ServerName[48];
  26. int        ServerType;
  27. unsigned int    ServerSocket;
  28. {
  29.     SAPData        *SAPDataEntity;
  30.     ECB            *SAPECB;
  31.     IPXPacket    *SAPPacket;
  32.     void        SAPWaitESRHandler();
  33.     void        SAPAdvertiseESRHandler();
  34.  
  35.     /* Allocate memory for ECB, IPXPacket, and SAPData Fragment */
  36.     SAPECB = (ECB *)calloc( 1, sizeof( ECB ) );
  37.     SAPDataEntity = (SAPData *)calloc( 1, sizeof( SAPData ) );
  38.     SAPPacket = (IPXPacket *)calloc( 1, sizeof( IPXPacket ) );
  39.  
  40.     /* Initialize the variables for the SAP IPXPacket. */
  41.     /* Notice that I broadcast on socket 452h (The SAP Socket) */
  42.     /* You need not have the socket open to send on the socket. */
  43.     SAPPacket->PacketType = (unsigned char)4;
  44.     SAPPacket->PacketLength = IntSwap( sizeof( IPXPacket ) );
  45.     IPXGetInternetworkAddress( (unsigned char *)SAPPacket->Destination.Network );
  46.     /* Broadcast on the local network, thus the 0xFFs */
  47.     memset( SAPPacket->Destination.Node, 0xFF, 6 );    
  48.     SAPPacket->Destination.Socket = 0x5204;
  49.  
  50.     /* I initialize the SAP data packet.  See the SAP document for details. */
  51.     SAPDataEntity->InfoType = IntSwap( 2 );
  52.     SAPDataEntity->ServerType = IntSwap( ServerType );
  53.     strcpy( SAPDataEntity->ServerName, ServerName);
  54.     IPXGetInternetworkAddress( (unsigned char *)SAPDataEntity->Address.Network );
  55.     SAPDataEntity->IntermediateNetworks = IntSwap( 1 );
  56.     SAPDataEntity->Address.Socket = ServerSocket;
  57.  
  58.     /* Initialize the ECB. */
  59.     SAPECB->ESRAddress = (char far *)SAPWaitESRHandler;
  60.     SAPECB->InUseFlag = 0;
  61.     SAPECB->FragmentCount = 2;
  62.     SAPECB->ECBSocket = 0x5204;
  63.     memset( SAPECB->ImmediateAddress, 0xFF, 6 );
  64.     SAPECB->FragmentDescriptor[0].Address = (char far *)SAPPacket;
  65.     SAPECB->FragmentDescriptor[0].Size = sizeof (IPXPacket );
  66.     SAPECB->FragmentDescriptor[1].Address = (char far *)SAPDataEntity;
  67.     SAPECB->FragmentDescriptor[1].Size = sizeof( SAPData );
  68.  
  69.     /* Keep track of where this ECB is for canceling later. */
  70.     DownECBPointer = SAPECB;
  71.  
  72.     IPXSendPacket( SAPECB );
  73.  
  74. }
  75.  
  76.  
  77. /* These two ESRs require some explanation. */
  78. /* When the IPXSendPacket is done above the ESR SAPWaitESR will be called */
  79. /* This ESR will immediately change the ESR to SAPAdvertiseESR and waits */
  80. /* one minute.  In one minute the SAPAdvertiseESR will be activated and */
  81. /* it will change the ESR to SAPWaitESR and then do a send packet. */
  82. /* These two ESRs will oscillate back and forth thus doing SAP calls. */
  83. void SAPWaitESR( wECB )
  84. ECB        *wECB;
  85. {
  86.     wECB->ESRAddress = (char far *)SAPAdvertiseESRHandler;
  87.     IPXScheduleIPXEvent( 60*18, wECB );        /* Every 60 Seconds */
  88. }
  89.  
  90.  
  91. void SAPAdvertiseESR( wECB )
  92. ECB        *wECB;
  93. {
  94.     wECB->ESRAddress = (char far *)SAPWaitESRHandler;
  95.     IPXSendPacket( wECB );
  96. }
  97.  
  98.  
  99. int StopSAPOscillationRoutines( ServerName, ServerType, ServerSocket )
  100. char    ServerName[48];
  101. int        ServerType;
  102. unsigned int    ServerSocket;
  103. {
  104.     SAPData        *wDataEntity;
  105.     ECB            *wECB;
  106.     IPXPacket    *wPacket;
  107.  
  108.  
  109.     /* First we will cancel the SAP oscillation ESRs. */
  110.     IPXCancelEvent( DownECBPointer );
  111.     while (DownECBPointer->InUseFlag)
  112.         ;
  113.  
  114.     /* Was the event canceled?  FC means yes. */
  115.     if (DownECBPointer->CompletionCode != 0xFC) 
  116.         return (-1);
  117.  
  118.     /* Now we will send out a IPX packet telling everyone that this */
  119.     /* server is down.  See the SAP document for details. */
  120.     wECB = (ECB *)calloc( 1, sizeof( ECB ) );
  121.     wDataEntity = (SAPData *)calloc( 1, sizeof( SAPData ) );
  122.     wPacket = (IPXPacket *)calloc( 1, sizeof( IPXPacket ) );
  123.  
  124.     wPacket->PacketType = (unsigned char)4;
  125.     wPacket->PacketLength = IntSwap( sizeof( IPXPacket ) );
  126.     IPXGetInternetworkAddress( (unsigned char *)wPacket->Destination.Network );
  127.     /* Broadcast on the local network, thus the 0xFFs */
  128.     memset( wPacket->Destination.Node, 0xFF, 6 );
  129.     wPacket->Destination.Socket = 0x5204;
  130.  
  131.     /* I initialize the SAP data packet.  See the SAP document for details. */
  132.     /* Tell everyone that I am going down. (Thus the 16 intermediate networks) */
  133.     wDataEntity->InfoType = IntSwap( 2 );
  134.     wDataEntity->ServerType = IntSwap( ServerType );
  135.     strcpy( wDataEntity->ServerName, ServerName);
  136.     IPXGetInternetworkAddress( (unsigned char *)wDataEntity->Address.Network );
  137.     wDataEntity->IntermediateNetworks = IntSwap( 16 );
  138.     wDataEntity->Address.Socket = ServerSocket;
  139.  
  140.     /* Initialize the ECB. */
  141.     wECB->FragmentCount = 2;
  142.     wECB->ECBSocket = 0x5204;
  143.     memset( wECB->ImmediateAddress, 0xFF, 6 );
  144.     wECB->FragmentDescriptor[0].Address = (char far *)wPacket;
  145.     wECB->FragmentDescriptor[0].Size = sizeof (IPXPacket );
  146.     wECB->FragmentDescriptor[1].Address = (char far *)wDataEntity;
  147.     wECB->FragmentDescriptor[1].Size = sizeof( SAPData );
  148.  
  149.     IPXSendPacket( wECB );
  150.     while( wECB->InUseFlag )
  151.         ;
  152.  
  153.     return (0);
  154.  
  155. }
  156.  
  157. /* Convert string to upper case */
  158. void ConvertToUpper(destination, source)
  159. char    *source, *destination;
  160. {
  161.     int    i;
  162.  
  163.     for (i=0;source[i];i++)
  164.         destination[i] = toupper(source[i]);
  165.     destination[i] = '\0';
  166. }
  167.  
  168.